package com.bc.mes.api.controller.schedule;

import com.bc.mes.common.api.CommonPage;
import com.bc.mes.common.api.CommonResult;
import com.bc.mes.mbg.model.schedule.CalTeam;
import com.bc.mes.service.calTeamService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @version 1.0
 * @Author 小胤
 * @Date 2024/7/11 11:01
 * @注释
 */
@Controller
@Api(tags = "CalTeamController", description = "班组管理")
@CrossOrigin(allowCredentials = "true")
@RequestMapping("/mes/cal/team")
public class CalTeamController {
    @Autowired
    private calTeamService calTeamService;
    /**
     * 查询班组
     */
    @ApiOperation("模糊查询用户、且分页")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<CalTeam>> list(@RequestParam(required = false) String teamCode,
                                                  @RequestParam(required = false) String teamName,
                                                  @RequestParam(required = false) String calendarType,
                                                  @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                  @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        Page page = PageHelper.startPage(pageNum, pageSize); // 开启分页
        List<CalTeam> list = calTeamService.select(teamCode, teamName, calendarType);
        Long pageTotal = page.getTotal();
        return CommonResult.success(CommonPage.restPage(list, pageTotal));
    }
}
